package com.cow.intercepter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class LoginHandlerIntercepter implements HandlerInterceptor {

	public void afterCompletion(HttpServletRequest req, HttpServletResponse rep, Object arg2, Exception arg3)
			throws Exception {

	}

	public void postHandle(HttpServletRequest req, HttpServletResponse rep, Object arg2, ModelAndView arg3)
			throws Exception {

	}

	public boolean preHandle(HttpServletRequest req, HttpServletResponse rep, Object arg2) throws Exception {
		rep.setHeader("Access-Control-Allow-Origin", req.getHeader("Origin"));
		rep.setHeader("Access-Control-Allow-Credentials", "true");
		rep.setHeader("Access-Control-Allow-Methods", "POST");
		rep.setHeader("Access-Control-Allow-Headers", "x-requested-with,content-type");
		// String[] urls={"/register.action","/sendMessage.action","/userImg"};
		// String requestURI = request.getRequestURI();
		// for(String url:urls){
		// if(requestURI.indexOf(url)>0){
		// return true;
		// }
		// }
		// HttpSession session = request.getSession();
		// String userId = (String) session.getAttribute("userId");
		// if (userId != null) {
		// // 登陆成功的用户
		// return true;
		// } else {
		// return false;
		// }
		return true;
	}

}
